window.addEventListener('load', function() {
    // 当用户按了回车或则点了另一个input的时候就自动检测 里面内容是否为true
    const rgPass = /^[a-z0-9_-]{6,16}$/; //密码正则
    const regtel = /^1[3|4|5|7|8]\d{9}$/; // 手机号码正则
    const ui_input = document.querySelector(".ui-input input");
    const err_msg = document.querySelector('.err-msg');

    ui_input.onblur = function() { // 离开验证
        if (regtel.test(this.value)) {
            replaceCut(err_msg, '手机格式正确', '#22D5BD', 'block');
        } else {
            replaceCut(err_msg, '手机格式错误', 'red', 'block')
        }
    }

    const pass = document.querySelector('.pass');
    console.log(pass)
    const verify = document.querySelector('.verify');
    console.log(verify)
    pass.onblur = function() {
        console.log(1)
        if (rgPass.test(this.value)) {
            replaceCut(verify, '密码格式正确', '#22D5BD', 'block');
        } else {
            replaceCut(verify, '密码格式错误', 'red', 'block');
        }
    }

    const sms_button = document.querySelector('.sms-button');
    sms_button.onclick = function() {
        console.log(1)
        this.className = "pointer sms-button";
        let num = 60;
        let timer = setInterval(function() {
            // console.log(this)
            sms_button.innerHTML = num + ' 秒';
            num--;
            if (num == 0) {
                sms_button.innerHTML = '获取验证码';
                sms_button.className = "sms-button pointerClick";
                clearInterval(timer);
                timer = null;
            }

        }, 1000);
    }




    function replaceCut(obj, message, color, dis) {
        obj.innerHTML = message;
        obj.style.color = color;
        obj.style.display = dis;
    }
});